package com.basic.aqs;

import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class SemaphoreTest {

	private static final Semaphore SEMAPHORE = new Semaphore(1);
	
	public static void main(String[] args) {
		Thread t1 = new Thread(new Runnable() {
			public void run() {
				try {
					SEMAPHORE.acquire(1);
					System.out.println("t1 执行了！");
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}finally{
					SEMAPHORE.release(1);
				}
			}
		});
		
		Thread t2 = new Thread(new Runnable() {
			public void run() {
				try {
					SEMAPHORE.acquire(1);
					System.out.println("t2 执行了！");
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}finally{
					SEMAPHORE.release(1);
				}
			}
		});
		t1.start();
		t2.start();
	}
}
